from django.db import models


class Artical(models.Model):
    title = models.CharField(max_length=1024, blank=False)
    html_path = models.CharField(max_length=1024, blank=True)
    updatets = models.DateTimeField(auto_now=True)
    createts = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'artical'
        managed = False


class Tag(models.Model):
    tag_name = models.CharField(max_length=1024)
    updatets = models.DateTimeField(auto_now=True)
    createts = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'tag'
        managed = False


class RArticalTag(models.Model):
    articalid = models.ForeignKey(to='Artical',
                                  to_field='id',
                                  db_column='articalid',
                                  related_name='artical_tags',
                                  on_delete=models.CASCADE)
    tagid = models.ForeignKey(to='Tag',
                              to_field='id',
                              db_column='tagid',
                              related_name='tag_articals',
                              on_delete=models.CASCADE)

    class Meta:
        db_table = 'r_artical_tag'
        unique_together = ('articalid', 'tagid')
        managed = False


class Author(models.Model):
    first_name = models.CharField(max_length=1024)
    mid_name = models.CharField(max_length=1024, blank=True)
    last_name = models.CharField(max_length=1024)
    des = models.CharField(max_length=1024, blank=True)
    updatets = models.DateTimeField(auto_now=True)
    createts = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'author'
        managed = False


class RArticalAuthor(models.Model):
    articalid = models.ForeignKey(to='Artical',
                                  to_field='id',
                                  db_column='articalid',
                                  related_name='atrical_authors',
                                  on_delete=models.CASCADE)
    authorid = models.ForeignKey(to='Author',
                                 to_field='id',
                                 db_column='authorid',
                                 related_name='author_articals',
                                 on_delete=models.CASCADE)

    class Meta:
        db_table = 'r_artical_author'
        managed = False


class Category(models.Model):
    cate_name = models.CharField(max_length=1024, blank=False)
    cate_desc = models.CharField(max_length=1024, blank=True, null=True)
    updatets = models.DateTimeField(auto_now=True)
    createts = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'category'
        managed = False


class RArticalCategory(models.Model):
    articalid = models.ForeignKey(to='Artical',
                                  to_field='id',
                                  db_column='articalid',
                                  related_name='artical_categories',
                                  on_delete=models.CASCADE)
    categoryid = models.ForeignKey(to='Category',
                                   to_field='id',
                                   db_column='categoryid',
                                   related_name='category_articals',
                                   on_delete=models.CASCADE)

    class Meta:
        db_table = 'r_artical_category'
        managed = False
